<?php
/**
 * @name 视频管理控制器
 * @namespace app\admin\controller;
 * @use app\common\controller\AdminBase;
 * @date 2016-8-31
 * @author zhibo
 */
namespace app\admin\controller;
use app\common\controller\AdminBase;
class Video extends AdminBase {
    protected function _initialize(){
        $this->mod = model('stream/Video');
    }
    /**
     * @name 回放列表
     */
    public function index(){
        $this->pageTitle = '回放视频列表';
        //条件
        $this->setConfig();
        $this->video_location && $map['video_location'] = ['like', '%' . $this->video_location . '%'];
        $this->video_title && $map['video_title'] = ['like', '%' . $this->video_title . '%'];
        $status = (int)$this->status - 1;
        if($this->status && $status >= 0){
            $map['status'] =  $status >=3 ? ['>',3] : $status;
        }
        $list = $this->mod->getPlayBackList($map,14,'vid desc',true);
        $this->assign('list',$list);
        return $this->fetch();
    }
    protected function setConfig(){
        $config = [
            'searchKey' =>  [
                'video_location' => [
                    'type'  => 'input',//输入框类型
                    'value_default' => $this->video_location,//默认值
                    'name'  => '地区',//名称
                    'info'  => '输入地区进行筛选',//提示文字
                    'text_max' => 5,//允许的最长字数
                ],
                'video_title' => [
                    'type'  => 'input',
                    'value_default' => $this->video_title,
                    'name'  => '视频标题',
                    'info'  => '输入视频标题搜索'
                ],
                'status'   =>  [
                    'type'  => 'select',//下拉列表
                    'value' => ['全部',1=>'处理完成',2=>'等待处理',3=>'正在处理',4=>'处理失败',5=>'无效视频'],//可选项
                    'value_default' => (int)$this->status ?:0,//默认选择key
                    'name'  => '视频处理状态',//名称
                ]
            ],
            'searchPostUrl' => U('admin/Video/index'),//搜索提交的地址
            'openBox'  => isset($this->data['video_location']) ? true : false,//是否默认打开搜索框
        
        ];
        $this->searchConfig($config);
    }
    /**
     * @name 删除回放视频
     */
    public function delVideo()
    {
        if(IS_POST)
        {
            $id = decrypt_id($this->id);
            if ($id)
            {
                if(M('video')->where(array('vid'=>$id))->save(array('is_del'=>1)))
                {
                    return ['status' => 1, 'data' => ['info'=>'删除成功','jumpurl' => U('admin/Video/index')]];
                }else
                {
                    return ['status'=>0,'message'=>'删除失败'];
                }
            }else
            {
                return ['status'=>0,'message'=>'视频信息不存在'];
            }
        }
    }
}